﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YwhCore
{
    public class InhabitantService
    {
        public static QueryRsp<Inhabitant> Save(Inhabitant inhabitant)
        {
            QueryRsp<Inhabitant> rsp = new QueryRsp<Inhabitant>();

            ConfigService.Fsql.InsertOrUpdate<Inhabitant>().SetSource(inhabitant).ExecuteAffrows();

            return rsp;
        }

        public static QueryRsp<Inhabitant> List(int PageNumber, int PageSize, int roomId = 0)
        {
            long l = 0;
            QueryRsp<Inhabitant> query = new QueryRsp<Inhabitant>();
            //if (roomId == 0)
            //{
            //    query.Items = ConfigService.Fsql.Select<Inhabitant>().Count(out l).Page(PageNumber, PageSize).ToList();
            //}
            //else
            //{
            //    query.Items = ConfigService.Fsql.Select<Inhabitant>().Where(f => f.RoomId == roomId).Count(out l).Page(PageNumber, PageSize).ToList();
            //}

            //foreach (var item in query.Items)
            //{
            //    item.Room = ConfigService.Fsql.Select<Room>().Where(f => f.RoomId == item.RoomId).First();
            //}

            query.Items = ConfigService.Fsql.Select<Inhabitant>().Count(out l).Page(PageNumber, PageSize).ToList();
            query.Total = (int)l;
            return query;
        }
    }
}
